﻿using System.ComponentModel;
using System.Net;
using Mini.Common;

namespace Mini.DownloadTool
{
    public partial class MainForm
    {
        private bool _isStart = false;
        private void EventRegister()
        {
            // Event of About | Option | Exit | Form
            RegisterEventStatic();
            // Event of Start | Validation After Start
            RegisterEventSystem();
            // Event and process status of Download
            DownloadEvent();

        }
        private void RegisterEventStatic()
        {
            var eventStatic = new EventStatic();
            btnAbout.Click += eventStatic.btnAbout_Click;
            btnOption.Click += eventStatic.btnOption_Click;
            btnExit.Click += eventStatic.btnExit_Click;
            FormClosed += eventStatic.MainForm_FormClosed;
            Load += eventStatic.MainForm_Load;

            txtPageName.KeyDown += textBox_KeyDown;
            txtPageLink.KeyDown += textBox_KeyDown;
        }

        private void DownloadEvent()
        {
            DownloadHelper.Completed += Completed;
            DownloadHelper.ProgressChanged += ProgressChanged;
        }

        private void RegisterEventSystem()
        {
            var eventSystem = new EventSystem(folderBrowserDialog);
            txtSaveTo.Click += eventSystem.SaveTo_FindFolder;
            btnFolderBrowser.Click += eventSystem.SaveTo_FindFolder;
            btnStart.Click += btnStart_Click;
            btnAddPage.Click += btnAddPage_Click;
            btnClearData.Click += btnClearData_Click;
        }

        private void SetStatusButtonStart(bool isStatus)
        {
            if (isStatus)
            {
                btnStart.Image = Properties.Resources._356;
                btnStart.Text = @"Loading";
            }
            else
            {
                btnStart.Image = Properties.Resources.Play;
                btnStart.Text = @"";
            }
            _isStart = isStatus;
        }

        private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
        {
            ProcessBar.Value = e.ProgressPercentage;
        }
        private void Completed(object sender, AsyncCompletedEventArgs e)
        {

        }
    }
}
